package ar.edu.unicen.pladema.ui.mywidgets;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import ar.edu.unicen.pladema.main.SWTUtils;
import ar.edu.unicen.pladema.resources.ResourceManager;
import ar.edu.unicen.pladema.ui.panel.AbstractPanel;

public class ZoomPanel extends AbstractPanel {
	private Group group;
	private int value;
	private Label valueLabel;
	private Text valueText;
	
	public ZoomPanel(Composite parent) {
		super(parent);
	}

	@Override
	protected void createWidgets() {
		group = new Group(this, SWT.SHADOW_ETCHED_IN);
		valueLabel = new Label(group, SWT.NONE);
		valueText = new Text(group, SWT.BORDER);

		group.setText(ResourceManager.getInstance().getText("ZOOM_TITLE"));
		valueLabel.setText(ResourceManager.getInstance().getText("ZOOM_VALUE"));
	}

	@Override
	protected void layoutWidgets() {
		this.setLayout(new FillLayout(SWT.VERTICAL));
		group.setLayout(new FormLayout());
		valueLabel.setLayoutData(SWTUtils.createRightFormData(5));
		valueText.setLayoutData(SWTUtils.createFullLeftFormData(valueLabel));
	}
	public void setValue(int v) {
		this.value = v;
		this.valueText.setText(Integer.toString(value));
	}
	public void setValue(String v) {
		try {
			value = Integer.parseInt(v);
			setValue(value);
		} catch (Exception e) {
			
		}
	}

	/**
	 * @return the width
	 */
	public int getValue() {
		try {
			value = Integer.parseInt(valueText.getText());
			return value;
		} catch (Exception e) {
			
		}
		valueText.setText(Integer.toString(value));
		return value;
	}

}
